<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<?php

if($_GET['_a']==1)
{
	$id = $_GET['_d']; 
	
	$page = $_GET['page'];
	$st = $_REQUEST['_st'];
	$title = $_POST['title'];
	$desc = mysql_escape_string($_POST['maincont']);
	$status = $_POST['status'];
	
	$q = mysql_fetch_array(mysql_query("select gadget_image  from  gadget where gadget_id='".$_POST['hid']."'"));
	
	if($_FILES["upload"]["name"]=="")
	{
		 $file=$q['gadget_image'];	
	
	}
	
	if($_FILES["upload"]["name"]!="")
	{
		
	 $path ="../uploads/gadget_images/".$q["gadget_image"];
	  
	 @unlink($path);
	$file=gmdate('YmdHis').$_FILES["upload"]["name"] ;
     move_uploaded_file($_FILES["upload"]["tmp_name"],"../uploads/gadget_images/".$file);

	}
	
mysql_query("update gadget set gadget_name='$title', gadget_desc='$desc',gadget_image='".$file."', active_status='$status', modified_datetime=now() where gadget_id='$id'") or die(mysql_error());
	echo "<script>window.location='index.php?tc=gadget&_s=1';</script>";
}
$id = $_REQUEST['_d'];
$page = $_REQUEST['page'];
$st = $_REQUEST['st'];

if($_REQUEST['_s'] == 1)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Updated Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<?php
$st = $_REQUEST['st'];
$q = mysql_fetch_array(mysql_query("select * from gadget where gadget_id='$id'"));

//$u = mysql_fetch_array(mysql_query("select * from users where Id='$q[UserId]'"));
?>

<form name="edgadget" action="index.php?tc=gadget_view&_d=<?php echo $id;?>&page=<?php echo $page;?>&_a=1&_st=<?php echo $st;?>" method="post" enctype="multipart/form-data">
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
<thead>
<input type="hidden" name="hid" value="<?php echo $q["gadget_id"];?>" />
<tr>
	<td colspan="3" align="left">
        <div style="float:left">Gadget</div>
        <div style="float:right"><a href="index.php?tc=gadget&page=<?php echo $page;?>&st=<?php echo $st;?>">Back</a></div>
    </td>
</tr>
</thead>
<tr>
	<td align="right" width="250">Gadget Name</td>
    <td colspan="2" align="left"><input type="text" name="title" value="<?php echo $q["gadget_name"];?>" ></td>
</tr>
<tr>
	<td align="right" width="250">Gadget Description</td>
    <td colspan="2" align="left">
    <textarea name="maincont" id="maincont" class="textarea" cols="45" rows="8"><?php echo stripslashes($q["gadget_desc"]);?></textarea>
        <script type="text/javascript">CKEDITOR.replace( 'maincont',{skin : 'kama'});</script>
        
   
     </td>
</tr>
<tr>
	<td align="right" width="250">Gadget Image</td>
    <td align="left"><input type="file" name="upload" /><img src="../uploads/gadget_images/<?php echo $q["gadget_image"];?>" width="40px" />
    </td>
</tr>
<tr>
	<td align="right" width="150">Status</td>
    <td colspan="2" align="left">
    	<select name="status">
        	<option value="0" <?php if($q["active_status"]==0) echo "selected";?>>Pending</option>
            <option value="1" <?php if($q["active_status"]==1) echo "selected";?>>Approved</option>
       	</select>     
    </td> 
</tr>
<tr>
	<td colspan="3" style="padding-left:250px;">
    	<input type="submit" value="Update" >&nbsp;&nbsp;
    </td>
</tr>        
 
</table>
</form>